#include "transaction_object_container.h"

using namespace boost;

transaction_object_container::transaction_object_container()
{
}

bool transaction_object_container::insert(void* ptr, transaction_object_t* obj)
{
	write_lock_t lock(mutex_);

	std::pair<unordered_map<void*, transaction_object_t*>::iterator, bool> res = container_.insert(std::pair<void*, transaction_object_t*>(ptr, obj));

	return res.second;
}

bool transaction_object_container::erase(void* ptr)
{
	write_lock_t lock(mutex_);

	return (container_.erase(ptr) != 0);
}

transaction_object_t* transaction_object_container::find(void *ptr)
{
	read_lock_t lock(mutex_);

	unordered_map<void*, transaction_object_t*>::iterator iter = container_.find(ptr);
	if (iter == container_.end())
	{
		return NULL;
	}

	return iter->second;
}
